package com.by.service;

import com.by.mapper.ReportMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapper reportMapper;

    @Override
    public Map<String, Object> getMemberReport() {

        List<Integer> memberCountList = new ArrayList<>();
        List<String> regTimeList = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();

        //当前时间
        Calendar calendar = Calendar.getInstance();
        //穿越-12个月
        calendar.add(Calendar.MONTH, -12);//2023-01

        for (int i = 0; i < 12; i++) {
            calendar.add(Calendar.MONTH, 1);//2023-02,2024-01
            String dateStr = new SimpleDateFormat("yyyy-MM").format(calendar.getTime());
            regTimeList.add(dateStr);
            int memberCount = reportMapper.getMemberCountByRegTime(dateStr);
            memberCountList.add(memberCount);
        }

        map.put("months", regTimeList);
        map.put("memberCount", memberCountList);

        return map;
    }

    @Override
    public List<Map<String, Object>> getSetmealReport() {
        return reportMapper.getSetmealReport();
    }
}
